//
//  ApplicationSupport.m
//  TrainFinder3
//
//  Created by 饶首建 on 17/2/28.
//  Copyright © 2017年 com.ikamobile.trainfinder3. All rights reserved.
//

#import "ApplicationSupport.h"
#import "BaseNaviVC.h"

#import "AppData.h"
#import "MainVC.h"
#import "ListTVC.h"

@implementation ApplicationSupport

+ (UITabBarController *)configureApplication:(NSDictionary *)launchOptions{
    MainVC *mainVC = [[MainVC alloc]init];
    mainVC.view.backgroundColor = DEFAULT_BACKGROUND_COLOR;
//    mainTvc.tabBarItem.badgeValue = @"1";
    mainVC.title = @"主页";
    mainVC.tabBarItem.image = [UIImage imageNamed:@"taxi"];
    mainVC.tabBarItem.selectedImage = [UIImage imageNamed:@"user"];
    
    ListTVC *listTvc = [[ListTVC alloc]init];
    listTvc.view.backgroundColor = DEFAULT_BACKGROUND_COLOR;
    listTvc.title = @"管理";
    listTvc.tabBarItem.image = [UIImage imageNamed:@"order"];
    listTvc.tabBarItem.selectedImage = [UIImage imageNamed:@"order"];
    
    
    BaseNaviVC *navC1 = [[BaseNaviVC alloc] initWithRootViewController:mainVC];
    BaseNaviVC *navC2 = [[BaseNaviVC alloc] initWithRootViewController:listTvc];
    
    UITabBarController *tabBarC = [[UITabBarController alloc] init];
    
    tabBarC.viewControllers = @[navC1, navC2];
    
    [self addThirdPartySupport];
    [self autoLogin];
    //初始化app
    [AppData sharedAppData];
    
    return tabBarC;
}

+ (void)autoLogin{
    //TODO
}

+ (void)addThirdPartySupport{
    // 将NSlog打印信息保存到Document目录下的文件中
//    [self redirectNSlogToDocumentFolder];
    
}

+ (void)redirectNSlogToDocumentFolder{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [paths objectAtIndex:0];
    NSString *fileName = [NSString stringWithFormat:@"dr.log"];// 注意不是NSData!
    NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName];
    // 先删除已经存在的文件
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    [defaultManager removeItemAtPath:logFilePath error:nil];
    // 将log输入到文件
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
}

@end
